home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
tpl60n19.zip
/
TESTPRGS.ZIP
/
UNIT1.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-02-27
|
23KB
|
701 lines
{$a+,n-,x-,s-,i-,r-,b-,v-}
unit Unit1;
interface
uses mainvars;
procedure start;
procedure mile2060;
implementation
procedure start;
begin (* PARA *)
{First two assignments use integer right-hand sides.}
Zero := 0;
One := 1;
Two := One + One;
Three := Two + One;
Four := Three + One;
Five := Four + One;
Eight := Four + Four;
Nine := Three * Three;
TwentySeven := Nine * Three;
ThirtyTwo := Four * Eight;
TwoForty := Four * Five * Three * Four;
MinusOne := -One;
Half := One / Two;
OneAndHalf := One + Half;
NoErrors [Failure] := 0;
NoErrors [SeriousDefect] := 0;
NoErrors [Defect] := 0;
NoErrors [Flaw] := 0;
PageNo := 0;
{=============================================}
Milestone := 0;
{=============================================}
writeln ('Type any character to start the program.');
{ assign(input,'con:');} { for TURBO Pascal version 2 }
{ reset (input); } { for old Cray Pascal }
while not eoln (input) do
read (input, ch);
Instructions;
Pause;
Heading;
Pause;
Characteristics;
Pause;
History;
{=============================================}
Milestone := 7;
{=============================================}
Pause;
writeln ('Program is now RUNNING tests on small integers:');
TestCondition (Failure, (Zero + Zero = Zero) and (One - One = Zero)
and (One > Zero)
and (One + One = Two), ' 0+0<>0 or 1-1<>0 or 1<=0 or 1+1<>2 '
);
Z := - Zero;
if Z <> 0.0 then
begin
NoErrors [Failure] := NoErrors [Failure] + 1;
writeln ('Comparison alleges that -0.0 is Non-zero!');
U2 := 0.001;
Radix := 1;
TestPartialUnderflow;
end;
TestCondition (Failure, (Three = Two + One) and (Four = Three + One)
and (Four + Two * (- Two) = Zero)
and (Four - Three - One = Zero),
' 3<>2+1, 4<>3+1, 4+2*(-2)<>0 or 4-3-1<>0');
TestCondition (Failure, (MinusOne = - One)
and (MinusOne + One = Zero ) and (One + MinusOne = Zero)
and (MinusOne + abs (One) = Zero)
and (MinusOne + MinusOne * MinusOne = Zero),
'-1+1<>0, -1+abs(1)<>0 or -1+(-1)*(-1)<>0');
TestCondition (Failure, Half + MinusOne + Half = Zero,
' 1/2 + (-1) + 1/2 <> 0 ');
{=============================================}
Milestone := 10;
{=============================================}
TestCondition (Failure, (Nine = Three * Three)
and (TwentySeven = Nine * Three) and (Eight = Four + Four)
and (ThirtyTwo = Eight * Four)
and (ThirtyTwo - TwentySeven - Four - One = Zero),
'9<>3*3, 27<>9*3, 32<>8*4 or 32-27-4-1<>0');
TestCondition (Failure, (Five = Four + One)
and (TwoForty = Four * Five * Three * Four)
and (TwoForty / Three - Four * Four * Five = Zero)
and ( TwoForty / Four - Five * Three * Four = Zero)
and ( TwoForty / Five - Four * Three * Four = Zero),
'5<>4+1,240/3<>80,240/4<>60, or 240/5<>48');
if NoErrors [Failure] = 0 then
begin
writeln (' -1, 0, 1/2, 1, 2, 3, 4, 5, 9, 27, 32 & 240 are O.K.');
writeln
end;
writeln ('Searching for Radix and Precision.');
W := One;
repeat
W := W + W;
Y := W + One;
Z := Y - W;
Y := Z - One;
until (MinusOne + abs (Y) >= Zero);
{.. now W is just big enough that |((W+1)-W)-1| >= 1 ...}
Precision := 0;
Y := One;
repeat
Radix := W + Y;
Y := Y + Y;
Radix := Radix - W;
until (Radix <> Zero);
if Radix < Two then
Radix := One;
writeln ('Radix = ', Radix);
if Radix <> 1 then
begin
W := One;
repeat
Precision := Precision + One;
W := W * Radix;
Y := W + One;
until (Y - W) <> One;
{... now W = Radix^Precision is barely too big to satisfy (W+1)-W = 1
...}
end;
U1 := One / W;
U2 := Radix * U1;
writeln ('Closest relative separation found is U1 = ', U1);
writeln;
writeln ('Recalculating radix and precision');
E0 := Radix;
E1 := U1;
E9 := U2;
{save old values}
X := Four / Three;
Third := X - One;
F6 := Half - Third;
X := F6 + F6;
X := abs (X - Third);
if X < U2 then
X := U2;
{... now X = (unknown no.) ulps of 1+...}
repeat
U2 := X;
Y := Half * U2 + ThirtyTwo * U2 * U2;
Y := One + Y;
X := Y - One;
until (U2 <= X) or (X <= Zero);
{... now U2 = 1 ulp of 1 + ... }
X := Two / Three;
F6 := X - Half;
Third := F6 + F6;
X := Third - Half;
X := abs (X + F6);
if X < U1 then
X := U1;
{... now X = (unknown no.) ulps of 1 -... }
repeat
U1 := X;
Y := Half * U1 + ThirtyTwo * U1 * U1;
Y := Half - Y;
X := Half + Y;
Y := Half - X;
X := Half + Y;
until (U1 <= X) or (X <= Zero);
{... now U1 = 1 ulp of 1 - ... }
if U1 = E1 then
writeln (' confirms closest relative separation U1 .')
else
writeln (' gets better closest relative separation U1 = ', U1);
W := One / U1;
F9 := (Half - U1) + Half;
Radix := Int (0.01 + U2 / U1);
if Radix = E0 then
writeln ('Radix confirmed.')
else
writeln ('MYSTERY: recalculated Radix = ', Radix);
TestCondition (Defect, Radix <= Eight + Eight,
'Radix is too big: roundoff problems ');
TestCondition (Flaw, (Radix = Two) or (Radix = 10)
or (Radix = One), 'Radix is not as good as 2 or 10. ');
end (*start*);
procedure mile2060;
begin
{=============================================}
Milestone := 20;
{=============================================}
TestCondition (Failure, F9 - Half < Half,
' (1-U1)-1/2 < 1/2 is FALSE, prog. fails?');
X := F9;
I := 1;
Y := X - Half;
Z := Y - Half;
TestCondition (Failure, (X <> One)
or (Z = Zero), 'Comparison is fuzzy,X=1 but X-1/2-1/2<>1');
X := One + U2;
I := 0;
{=============================================}
Milestone := 25;
{=============================================}
BMinusU2 := Radix - One;
BMinusU2 := (BMinusU2 - U2) + One;
if Radix <> One then
begin {... BMinusU2 = nextafter(Radix, 0) }
X := - TwoForty * ln (U1) / ln (Radix);
Y := Int (Half + X);
if abs (X - Y) * Four < One then
X := Y;
Precision := X / TwoForty;
Y := Int (Half + Precision);
if abs (Precision - Y) * TwoForty < Half then
Precision := Y;
{ Purify integers }
end;
if (Precision <> Int (Precision)) or (Radix = One) then
begin
writeln ('Precision cannot be characterized by an integer',
' number of sig. digits,');
writeln ('but, by itself, this is a minor flaw.');
end;
if Radix = One then
writeln ('logarithmic encoding has precision characterized',
'solely by U1.')
else
writeln ('The number of significant digits of the Radix is ',
Precision);
TestCondition (SeriousDefect, U2 * Nine * Nine * TwoForty < One,
' Precision worse than 5 decimal figures ');
{=============================================}
Milestone := 30;
{=============================================}
{ Test for extra-precise subepressions }
X := abs (((Four / Three - One) - One / Four) * Three - One / Four);
repeat
Z2 := X;
X := (One + (Half * Z2 + ThirtyTwo * Z2 * Z2)) - One;
until (Z2 <= X) or (X <= Zero);
Y := abs ((Three / Four - Two / Three) * Three - One / Four);
Z := Y;
X := Y;
repeat
Z1 := Z;
Z := (One / Two - ((One / Two - (Half * Z1 + ThirtyTwo * Z1 * Z1))
+ One / Two)) + One / Two;
until (Z1 <= Z) or (Z <= Zero);
repeat
repeat
Y1 := Y;
Y := (Half - ((Half - (Half * Y1 + ThirtyTwo * Y1 * Y1)) + Half
)) + Half;
until (Y1 <= Y) or (Y <= Zero);